package core;

import com.thoughtworks.selenium.*;
import reporting.*;
import util.*;

public class SeleneseTestCaseEx extends SeleneseTestCase {
	public static Action action;
	public static ActionSet actionset;
	public static Check check;
	public static Boolean configureTest = true;
	public static FileWork fw = new FileWork();
	public static DefaultSeleniumEx browser;	
	public static TestConfiguration tc = TestConfiguration.getInstance();
	public static SuiteConfiguration sc = SuiteConfiguration.getInstance();
	public static ReportEngine repEng;
	public static Util u = new Util();
	
	public SeleneseTestCaseEx(String name) {
		super(name);
	}
	
	public void setUp() {
		if (configureTest) {
			//Load properties
			tc.setEnv("_testname", this.getClass().getSimpleName());
			tc.loadLocalProperties("./src/test/" + this.getClass().getSimpleName());
			
			repEng = new ReportEngine();
			
			//Initialize reporting section
			browser = new DefaultSeleniumEx(getServerName(), getPort(), getBrowser(), tc.getEnv("mainurl"));
			action = new Action();
			actionset = new ActionSet();
			check = new Check();
			
			configureTest = false;
		}
	}

	/**
	 * @throws java.lang.Exception
	 */
	public void tearDown() throws Exception {
		repEng.reportStep();
	}
	
	public static String getServerName() {
		if (sc.getEnv("servername")== null) {
			return tc.getEnv("servername");
		} else {
			return sc.getEnv("servername");
		}
	}
	
	public static Integer getPort() {
		if (sc.getEnv("port")== null) {
			return Integer.parseInt(tc.getEnv("port"));
		} else {
			return Integer.parseInt(sc.getEnv("port"));
		}
		
	}
	
	public static String getBrowser() {
		if (sc.getEnv("browser")== null) {
			return tc.getEnv("browser");
		} else {
			return sc.getEnv("browser");
		}
	}
	
	public void putLocalProperty(String key, String value) {
			String fullPath = "./src/test/" + this.getClass().getSimpleName();
			tc.putLocalProperty(fullPath, key, value);
			tc.loadLocalProperties(fullPath);
	}		
	
}	
	
	
	
	